@extends('home/main/layout')
@section('title','购物车')
@section('introduce')
<style>
	#carttable th
	{
		text-align:center;
		font:bold 18px 黑体;
	}
	#carttable td
	{
		font:14px 宋体;
	}
</style>
@stop
@section('content')
<!--bottom-header-->
	<!--start-breadcrumbs-->
	<div class="breadcrumbs">
		<div class="container">
			<div class="breadcrumbs-main">
				<ol class="breadcrumb">
					<li><a href="{{asset('/')}}">首页</a></li>
					<li class="active">购物车</li>
				</ol>
			</div>
		</div>
	</div>
	<!--end-breadcrumbs-->
	<!--start-ckeckout-->
	<div class="ckeckout">
		<div class="container">
			<div class="ckeckout-top">
			<div class=" cart-items heading">
			 <h3>我的购物车 ({{$mycartc}})</h3><br>	
			<div class="table-responsive">
        	<table id="carttable" class="table table-bordered table-striped text-center">
	          <thead>
	          <tr>
	            <th>选择</th>
	            <th colspan="2">商品信息</th>
	            <th>购买数量</th>
	            <th>商品单价(物流价)(元)</th>
	            <th>小计(元)</th>
	            <th colspan="2">操作</th>
	          </tr>
	          </thead>
	          <form id="mainform" action="/order" method="get">
	          <tbody>
	          	@foreach($mycarts as $k=>$mycart)
	          	<tr>
					

					<td><input type="checkbox" name="cart_id[]" value="{{$mycart->cart_id}}"/></td>
					<td><a href="/single/{{$mycart->pro_id}}"><img src="/uploads/product/logo_pic/{{$mycart->logo_pic}}" style="width:50px;heihgt:50px;"></a></td>
					<td>
						<a href="/single/{{$mycart->pro_id}}">{{$mycart->title}}</a><br>
						<span>{{$mycart->pro_keyword}}</span>
					</td>
					<td>{{$mycart->buynum}}</td>
					<td>{{$mycart->sprice}}( {{$mycart->lprice}} )</td>
					<td>{{($mycart->sprice+$mycart->lprice)*$mycart->buynum}}</td>

					
					<td colspan="2"><a href="/cartdel?cart_id={{$mycart->cart_id}}"><button type="button" class="btn btn-danger btn-sm">删除</button></a></td>
					

	          	</tr>
	          	@endforeach
	          </tbody>
        	  <tfoot>
        	  	<tr>
        	  		<th colspan="2">
        	  			<button id="choose1" type="button" class="btn btn-primary">全选</button>
        	  			<button id="choose2" type="button" class="btn btn-primary">不选</button>
        	  			<button id="choose3" type="button" class="btn btn-primary">反选</button>

        	  			<script>
        	  			$(function(){
	        	  			$('#choose1').on('click',function(){
	        	  				$('[type=checkbox]').prop('checked',true);
	        	  				$('[type=checkbox]').attr('checked',true);

	        	  			});
	        	  			$('#choose2').on('click',function(){
	        	  				$('[type=checkbox]').prop('checked',false);
	        	  				$('[type=checkbox]').attr('checked',false);
	        	  			});
	        	  			$('#choose3').on('click',function(){
	        	  				var ckd=$('[type=checkbox]:checked');

	        	  				$('[type=checkbox]').prop('checked',true);
	        	  				$('[type=checkbox]').attr('checked',true);
	        	  				ckd.prop('checked',false);
	        	  				ckd.attr('checked',false);
	        	  			});
        	  			});

        	  			</script>
        	  		</th>
		            <th colspan="3"></th>
		            <th>总计：<span id="allprice">0.00</span></th>

		            <th><button id="allord"  class="btn btn-warning">去结算</button></th>

		            <th><button id="alldel"  class="btn btn-danger btn-sm">全部删除</button></th>
		            <script>
		            	$(function(){
			            	$('#allord').on('click',function(){
			            		$('#mainform').attr('action','/order');
			            		if($('[type=checkbox]:checked').length==0){
			            			alert('选择订单商品');
			            			return false;
			            			
			            		}else{
			            			return true;
			            		}
			            	});
			            	$('#alldel').on('click',function(){
			            		$('#mainform').attr('action','/cartdel');
			            		
			            	});
			            	//单点
			            	$('[type=checkbox]').on('click',function(){
			            		//console.log($(this).attr('value'));
			            		var price=new Array();
			            		//console.log($('[type=checkbox]:checked').length);
			            		if($('[type=checkbox]:checked').length!=0){
				            		for(i=0;i<=$('[type=checkbox]:checked').length-1;i++){
				            			price[i]=$('[type=checkbox]:checked').eq(i).parent().parent().children().eq(5).html();
				            		}
			            			//console.log(price);
			            			var allprice=eval(price.join('+'));
			            			//console.log(allprice);
			            			$('#allprice').html(allprice);
			            		}else{
			            			$('#allprice').html('0.00');

			            		}
			            		

			            	});
			            	//全选不选反选
			            	$('#choose1').on('click',function(){
			            		//console.log($(this).attr('value'));
			            		var price=new Array();
			            		//console.log($('[type=checkbox]:checked').length);
			            		if($('[type=checkbox]:checked').length!=0){
				            		for(i=0;i<=$('[type=checkbox]:checked').length-1;i++){
				            			price[i]=$('[type=checkbox]:checked').eq(i).parent().parent().children().eq(5).html();
				            		}
			            			//console.log(price);
			            			var allprice=eval(price.join('+'));
			            			//console.log(allprice);
			            			$('#allprice').html(allprice);
			            		}else{
			            			$('#allprice').html('0.00');

			            		}
			            		

			            	});
			            	$('#choose2').on('click',function(){
			            		//console.log($(this).attr('value'));
			            		var price=new Array();
			            		//console.log($('[type=checkbox]:checked').length);
			            		if($('[type=checkbox]:checked').length!=0){
				            		for(i=0;i<=$('[type=checkbox]:checked').length-1;i++){
				            			price[i]=$('[type=checkbox]:checked').eq(i).parent().parent().children().eq(5).html();
				            		}
			            			//console.log(price);
			            			var allprice=eval(price.join('+'));
			            			//console.log(allprice);
			            			$('#allprice').html(allprice);
			            		}else{
			            			$('#allprice').html('0.00');

			            		}
			            		

			            	});
			            	$('#choose3').on('click',function(){
			            		//console.log($(this).attr('value'));
			            		var price=new Array();
			            		//console.log($('[type=checkbox]:checked').length);
			            		if($('[type=checkbox]:checked').length!=0){
				            		for(i=0;i<=$('[type=checkbox]:checked').length-1;i++){
				            			price[i]=$('[type=checkbox]:checked').eq(i).parent().parent().children().eq(5).html();
				            		}
			            			//console.log(price);
			            			var allprice=eval(price.join('+'));
			            			//console.log(allprice);
			            			$('#allprice').html(allprice);
			            		}else{
			            			$('#allprice').html('0.00');

			            		}
			            		

			            	});
			            	
		            	});
		            </script>

	        	 </tr>
        	  </tfoot>
        	  </form>
        	</table>
       		</div>

@stop

